package com.jian.java;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.ActiveMQMessageProducer;
import org.apache.activemq.AsyncCallback;

import javax.jms.*;

/**
 * @author Jiange
 * @create 2021-05-27-15:49
 */
public class JsmProduce {
    public static void main(String[] args) throws JMSException {
        //创建连接工厂
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://192.168.48.131:61616");
        Connection connection = factory.createConnection();



        //两个参数一个是事务 一个是签收
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        //创建目的地 是队列还是主题
        Queue queue = session.createQueue("queue01");
        Topic jian = session.createTopic("jian");

        //创建消息的生产者
        MessageProducer producer = session.createProducer(queue);
        ActiveMQMessageProducer activeMQMessageProducer = (ActiveMQMessageProducer) session.createProducer(queue);
        activeMQMessageProducer.send(session.createTextMessage(""), new AsyncCallback() {
            @Override
            public void onSuccess() {

            }

            @Override
            public void onException(JMSException e) {

            }
        });
        producer.setDeliveryMode(1);
        connection.start();
        producer.send(session.createTextMessage("建哥最帅"));
        producer.close();
        session.close();
        connection.close();
    }
}
